<?php
/*
  $Id: customer_testimonials.php,v 1.3 2003/12/08 Exp $

  The Exchange Project - Community Made Shopping!
  http://www.theexchangeproject.org

  Copyright (c) 2000,2001 The Exchange Project

  Released under the GNU General Public License
  Contributed by http://www.seen-online.co.uk
*/

  require('includes/application_top.php');

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CUSTOMER_TESTIMONIALS);

  $location = ' &raquo; <a href="' . tep_href_link(FILENAME_CUSTOMER_TESTIMONIALS, '', 'NONSSL') . '" class="headerNavigation">' . NAVBAR_TITLE . '</a>';
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<base href="<?php echo (getenv('HTTPS') == 'on' ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<!-- body //-->
<table border="0" width="100%" cellspacing="3" cellpadding="3">
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
    </table></td>
<!-- body_text //-->
    <td width="100%" valign="top" style="padding-left: 20px;"><table border="0" width="100%" cellspacing="0" cellpadding="0" >
      <tr>
        <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading" colspan="2"><?php echo HEADING_TITLE; ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>
        <td><br><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td class="main">
            <?php
            if ($testimonial_id != '') {
                $full_testimonial = tep_db_query("select * FROM " . TABLE_CUSTOMER_TESTIMONIALS . " WHERE testimonials_id = '".(int)$testimonial_id."' LIMIT 1");
            }
            else {
                $full_testimonial = tep_db_query("select * FROM " . TABLE_CUSTOMER_TESTIMONIALS . " WHERE status = '1' order by rand()");
            }
            while ($testimonials = tep_db_fetch_array($full_testimonial)) {
                $testimonial_array[] = array('id' => $testimonials['testimonials_id'],
                                             'author' => $testimonials['testimonials_name'],
											 'location' => $testimonials['testimonials_location'],
											 'title' => $testimonials['testimonials_title'],
                                             'testimonial' => $testimonials['testimonials_html_text'],
                                             'word_count' => tep_word_count($testimonials['testimonials_html_text'], ' '),
                                             'url' => $testimonials['testimonials_url'],
                                             'url_title' => $testimonials['testimonials_url_title']);
                }
            require(DIR_WS_MODULES  . 'customer_testimonials.php');
            ?>
            </td>
          </tr>
        </table></td>
      </tr>
<?php

if ($HTTP_GET_VARS['action']) {
    switch ($HTTP_GET_VARS['action']) {
      case 'insert':
        $testimonials_id = tep_db_prepare_input((int)$HTTP_POST_VARS['testimonials_id']);
        $testimonials_title = tep_db_prepare_input($HTTP_POST_VARS['testimonials_title']);
        $testimonials_url = tep_db_prepare_input($HTTP_POST_VARS['testimonials_url']);
        $testimonials_url_title = tep_db_prepare_input($HTTP_POST_VARS['testimonials_url_title']);
        $testimonials_name = tep_db_prepare_input($HTTP_POST_VARS['testimonials_name']);
        $testimonials_location = tep_db_prepare_input($HTTP_POST_VARS['testimonials_location']);
        $html_text = tep_db_prepare_input($HTTP_POST_VARS['html_text']);

        $testimonials_error = false;
        $messageStack = ERROR_HEADER;
        if (empty($testimonials_title)) {
          $messageStack .= '['.ERROR_TESTIMONIALS_TITLE_REQUIRED.']';
          $testimonials_error = true;
        }
        if (empty($testimonials_name)) {
          $messageStack .= '['.ERROR_TESTIMONIALS_NAME_REQUIRED.']';
          $testimonials_error = true;
        }
        if (empty($html_text)) {
          $messageStack.= '['.ERROR_TESTIMONIALS_DESCRIPTION_REQUIRED.']';
          $testimonials_error = true;
        }

        if (!$testimonials_error) {
          $sql_data_array = array('testimonials_title' => $testimonials_title,
                                  'testimonials_url' => $testimonials_url,
                                  'testimonials_url_title' => $testimonials_url_title,
                                  'testimonials_name' => $testimonials_name,
								  'testimonials_location' => $testimonials_location,
                                  'testimonials_html_text' => $html_text);
         if ($HTTP_GET_VARS['action'] == 'insert') {
           $insert_sql_data = array('date_added' => 'now()',
                                     'status' => '0');
            $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
            tep_db_perform(TABLE_CUSTOMER_TESTIMONIALS, $sql_data_array);
            $testimonials_id = tep_db_insert_id();
          }
          echo '<tr><td colspan="2">' . tep_draw_separator('pixel_trans.gif', '1', '10') .' </td></tr>';
          echo '<tr><td class="main">'. TEXT_TESTIMONIALS_SUCCESSFUL .'</td><td class="main"></td></tr>';
          $testimonials_id = '';
           $testimonials_title = '';
           $testimonials_url = '';
           $testimonials_url_title = '';
           $testimonials_name = '';
		   $testimonials_location = '';
           $html_text = '';
        } else {
           echo '<tr><td colspan="2">' . tep_draw_separator('pixel_trans.gif', '1', '10') .' </td></tr>';
           echo '<tr><td class="main">'. $messageStack .'</td><td class="main"></td></tr>';

           $testimonials_id = tep_db_prepare_input($HTTP_POST_VARS['testimonials_id']);
           $testimonials_title = tep_db_prepare_input($HTTP_POST_VARS['testimonials_title']);
           $testimonials_url = tep_db_prepare_input($HTTP_POST_VARS['testimonials_url']);
           $testimonials_url_title = tep_db_prepare_input($HTTP_POST_VARS['testimonials_url_title']);
           $testimonials_name = tep_db_prepare_input($HTTP_POST_VARS['testimonials_name']);
		   $testimonials_location = tep_db_prepare_input($HTTP_POST_VARS['testimonials_location']);
           $html_text = tep_db_prepare_input($HTTP_POST_VARS['html_text']);
        }
        break;
    }
  }

?>
<tr><form name="customer_testimonial" method="post" action="<?php echo tep_href_link(FILENAME_CUSTOMER_TESTIMONIALS, 'action=insert', 'NONSSL'); ?>"  >
        <td><table align="center" width="100%" border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="main" align="center"><?php echo TEXT_TESTIMONIALS_INTRO; ?></td>
           </tr>
          <tr>
            <td class="main" align="center">************************</td>
           </tr>
		   <tr>
		    <td><table align="center" width="100%" border="0" cellspacing="0" cellpadding="0"><tr>
            <td class="main"><?php echo TEXT_TESTIMONIALS_TITLE; ?></td>
            <td class="main"><?php echo tep_draw_input_field('testimonials_title',  $testimonials_title, '', true); ?></td>
          </tr>
		  <tr>
            <td class="main"><?php echo TEXT_TESTIMONIALS_URL_TITLE; ?></td>
            <td class="main"><?php echo tep_draw_input_field('testimonials_url_title', $testimonials_url_title); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_TESTIMONIALS_URL; ?></td>
            <td class="main"><?php echo tep_draw_input_field('testimonials_url', $testimonials_url); ?></td>
          </tr>

          <tr>
            <td class="main"><?php echo TEXT_TESTIMONIALS_NAME; ?></td>
            <td class="main"><?php echo tep_draw_input_field('testimonials_name', $testimonials_name, '', true); ?></td>
          <tr>
		  <tr>
            <td class="main"><?php echo TEXT_TESTIMONIALS_LOCATION; ?></td>
            <td class="main"><?php echo tep_draw_input_field('testimonials_location', $testimonials_location); ?></td>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td valign="top" class="main"><?php echo TEXT_BANNERS_HTML_TEXT; ?></td>
            <td class="main"><?php echo tep_draw_textarea_field('html_text', 'soft', '130', '5', $html_text); ?></td>
          </tr></table></td></tr></tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td><table align="center" border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td align="center" class="main"><?php echo tep_image_submit('button_update1.gif', IMAGE_BUTTON_INSERT). '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_CUSTOMER_TESTIMONIALS, '', 'NONSSL') . '"></a> <a href="' . tep_href_link(FILENAME_DEFAULT, '', 'NONSSL') . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a></td>'; ?>
          </tr>
        </table></td>
      </form></tr>

    </table></td>
<!-- body_text_eof //-->
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- right_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
<!-- right_navigation_eof //-->
    </table></td>
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
